package com.easybuy.dao.impl;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

import com.easybuy.dao.BaseDao;
import com.easybuy.dao.ProductCategoryDao;
import com.easybuy.entity.ProductCategory;

public class ProductCategoryDaoImpl extends BaseDao implements ProductCategoryDao{

	private Connection conn;
	private PreparedStatement pstmt;
	private ResultSet rs;
	
	@Override
	public List<ProductCategory> findAll() {
		List<ProductCategory> list = new ArrayList<>();
		try {
			conn = super.getConnection();
			String sql = "select id,name,parentid,type,iconClass from easybuy_product_category";
			pstmt = conn.prepareStatement(sql);
			rs = pstmt.executeQuery();
			
			while (rs.next()) {
				
				ProductCategory category = new ProductCategory();
				category.setId(rs.getInt("id"));
				category.setName(rs.getString("name"));
				category.setParentId(rs.getInt("parentid"));
				category.setType(rs.getInt("type"));
				category.setIconClass(rs.getString("iconClass"));
				
				list.add(category);
			}
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
        	super.closeAll(conn, pstmt, rs);
        }
		return list;
	}

}
